cmake_minimum_required(VERSION 3.10)
set(CMAKE_CXX_STANDARD 11)
project(ji)

include(${CMAKE_SOURCE_DIR}/cmake/common.cmake)
set(CMAKE_CXX_FLAGS "-O3")
set(CMAKE_INSTALL_PREFIX "/usr/local/ev_sdk")
set(CMAKE_INSTALL_RPATH "/usr/local/ev_sdk/lib")
set(CMAKE_BUILD_TYPE "Release")
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) 

set(BMNNSDK /opt/sophon)

set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
set(CMAKE_ASM_COMPILER aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)
set(BM_LIBS bmlib bmrt bmcv yuv)
set(JPU_LIBS bmjpuapi bmjpulite)
set(OPENCV_LIBS opencv_imgproc opencv_core opencv_highgui opencv_imgcodecs opencv_videoio opencv_freetype)

include_directories(${BMNNSDK}/sophon-opencv-latest/include/opencv4/
                    ${BMNNSDK}/libsophon-current/include
                    ${BMNNSDK}/sophon-ffmpeg-latest/include
                   )
link_directories(${BMNNSDK}/sophon-opencv-latest/lib
                        ${BMNNSDK}/libsophon-current/lib
                        ${BMNNSDK}/sophon-ffmpeg-latest/lib)

set(BOOST_LIBS_DIR /usr/lib/aarch64-linux-gnu)
set(OPENCV_INCLUDE_DIR ${BMNNSDK}/sophon-opencv-latest/include/opencv4/)


#先编译三方库中的源码，并包含头文件路径
#jsoncpp相关头文件路径和源文件
include_directories(${CMAKE_SOURCE_DIR}/3rd/jsoncpp_simple/include)
add_subdirectory(${CMAKE_SOURCE_DIR}/3rd/jsoncpp_simple)
#配置点线框解析相关头文件路径和源文件
include_directories(${CMAKE_SOURCE_DIR}/3rd/wkt_parser/include)
add_subdirectory(${CMAKE_SOURCE_DIR}/3rd/wkt_parser)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
# 编译libji.so
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/src SRCS)
list(APPEND libji_SOURCES  ${SRCS})
add_library (${PROJECT_NAME} SHARED ${libji_SOURCES})


target_link_libraries(${PROJECT_NAME}
        ${OPENCV_LIBS}
        ${BM_LIBS}
        glog
        WKTParser
        jsoncpp
        -lavcodec
        -lavformat
        -lavutil
)

# Install libji.so
install(TARGETS ${PROJECT_NAME} DESTINATION lib)
# ---  END EV_SDK DEPENDENCIES  ---

# add test 
#add_subdirectory(${CMAKE_SOURCE_DIR}/test)

